<?php
session_start();
require_once("./include/membersite_config.php");
if($_SESSION['cur_href'] != $fgmembersite->GetSelfScript())
{
	$_SESSION['pre_href'] = $_SESSION['cur_href'];
	$_SESSION['cur_href'] = $fgmembersite->GetSelfScript();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><?PHP $fgmembersite->GetString('Sign up','Đăng ký')?></title>
<?PHP
require_once("./pre-config.php");
?>
</head> 
<body>
<?PHP
require_once("./main-nav.php");
?>
<div class="container">
    <div class="row">
<?PHP
    print '<div class="col-md-'.$_SESSION['main-div-left'].'">';
	print '</div>';
    print '<div class="col-md-'.$_SESSION['main-div-center'].'">';
?>
        <form id="mainform">
				<div id="notice-board">
					<?PHP $fgmembersite->GetErrorMessage()?>				
				</div>
				<div class="form-group">
					<h4 class="text-primary"><?PHP $fgmembersite->GetString('Sign up:','Đăng ký:')?></h4>
					<label for="inputfull_name"><?PHP $fgmembersite->GetString('Full name*','Họ và Tên:')?></label>
					<input type="text" class="form-control" name="full_name" id="full_name" value='<?php echo $fgmembersite->SafeDisplay('full_name'); ?>' maxlength="32"/>
					<label for="inputuser_name"><?PHP $fgmembersite->GetString('User name*','Tên đăng nhập*')?></label>
					<input type="text" class="form-control" name="user_name" id="user_name" value='<?php echo $fgmembersite->SafeDisplay('user_name'); ?>' maxlength="32"/>
					<label for="inputPassword"><?PHP $fgmembersite->GetString('Password*','Mật khẩu*')?></label>
					<input type="password" class="form-control" name="password" id="password" value='<?php echo $fgmembersite->SafeDisplay('password'); ?>' maxlength="32"/>
					<label for="inputConfirmPassword"><?PHP $fgmembersite->GetString('Confirm Password*','Xác định lại mật khẩu*')?></label>
					<input type="password" class="form-control" name="confirm_password" id="confirm_password" value='<?php echo $fgmembersite->SafeDisplay('confirm_password'); ?>'/>
					<label for="inputLanguage"><?PHP $fgmembersite->GetString('Language*','Ngôn ngữ*')?></label>
					<div class="radio">
						<label><input type="radio" name="vn" id="vn" value="1" checked> <?PHP $fgmembersite->GetString('Vietnamese','Tiếng Việt')?></label><br>
						<label><input type="radio" name="vn" id="en" value="0"> <?PHP $fgmembersite->GetString('English','Tiếng Anh')?></label>
					</div>					
					<label for="inputCaptcha">Captcha*</label>
					</br>
					<img src="image.php" id="img-captcha"/>
					<input type="button" value='<?PHP $fgmembersite->GetString('Reload','Tải lại')?>' onclick="$('#img-captcha').attr('src', 'image.php?rand=' + Math.random())" /> <br/>
					<input type="text" id="captcha" value="" />
				</div>
				<button id="submit" type="submit"  name='Submit' class="btn btn-success center-block"><?PHP $fgmembersite->GetString('Create','Đăng ký')?></button>
        </form>
	</div>
<?PHP
    print '<div class="col-md-'.$_SESSION['main-div-right'].'">';
	print '</div>';
?>	
    </div>
</div>
<?PHP
require_once("./footer.php");
?>
<script language="javascript">
$(document).ready(function()
{
	$('#submit').click(function()
	{
		// Lấy dự liệu
		var data = 
		{
			command : 'sign-up',
			full_name : $('#full_name').val(),
			user_name : $('#user_name').val(),
			password : $('#password').val(),
			confirm_password : $('#confirm_password').val(),
			vn : $("input[name='vn']:checked").val(),
			captcha : $('#captcha').val()
		};
		
		$.ajax(
		{
			type : 'POST',
			dataType : 'json',
			url : 'ajax_validate.php',
			data : data,
			success : function (result)
			{
				if (result['error'] == 'success')
				{
//					window.location.href= document.referrer;
					window.location.href = "search-group.php"
				}
				else
				{
					document.getElementById("notice-board").className = 'alert alert-danger fade in';
					document.getElementById("notice-board").innerHTML = '<strong>Error! ' + result['error'] + '</strong>';
				}
			},
			error : function ()
			{
				document.getElementById("notice-board").className = 'alert alert-danger fade in';
				document.getElementById("notice-board").innerHTML = '<strong>Error! Error in processing.</strong>';
			}
		});
		return false;
	});
});
</script>
</body>
</html>
